﻿/// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2-vsdoc.js" /> 
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            
$(document).ready(function () {
    //$("#contactContent").html($("#SuccessContactMessage").html()); // remove

    $(".contactMessage").keyup(function () {
        var left = 1000 - $(this).val().length;
        $("#charsRemaining").text(left + "/1000 characters remaining.");      
    });
    
    submitBtn.click(function (e) {
        e.preventDefault();
        $(".errorAstrix").hide();
        var hasErrors = false;
        if (nameTbx.val() == "") {
            hasErrors = true;
            $("#name_validate").show();
        }
        if (EmailTbx.val() == "" || !re.test(EmailTbx.val())) {
            hasErrors = true;
            $("#email_validate").show();
        }
        if (MessageTbx.val() == "") {
            hasErrors = true;
            $("#message_validate").show();
        }

        if (hasErrors) {
            return false;
        } 
        else {
            var data = { name: nameTbx.val(), email: EmailTbx.val(), message: MessageTbx.val() };
            Tapt.DoAjaxPro(data, "SendMessage", function (s) {
                if (JSON.parse(s).value) {
                    $(".successMessageSpan").text($(".successMessageSpan").text().replace("{0}", nameTbx.val()));
                    $("#contactContent").html($("#SuccessContactMessage").html());
                }
            });
        }
    });
});